home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Telecom / Internet / Internet A-M / MacHTTP 1.2.3 ƒ / sample.script < prev    next >
Encoding:
Text File  |  1993-10-06  |  2.0 KB  |  50 lines  |  [TEXT/ttxt]

  1. -- This script demonstrates using AppleScript with MacHTTP to generate
  2. -- dynamic World Wide Web documents.
  3. --
  4. -- MacHTTP will only read and execute scripts that have been saved as
  5. -- text only. Once the script is loaded by MacHTTP, it is passed to the default
  6. -- scripting system (usually AppleScript) for your server for execution.
  7. -- MacHTTP prepends the script's source code with a line that is the equivalent of:
  8. -- set http_request to "<request from client>"
  9. -- where <request from client> is the actual data received from the WWW client.
  10. --
  11. -- The result of the script execution is then returned to the client as a HTML
  12. -- document. The following script shows how to turn AppleScript results into HTML.
  13.  
  14. set file_path to ":" -- if this script is in a subdirectory below MacHTTP, change this to the proper relative path
  15.  
  16. -- Create the title for the HTML document
  17.  
  18. set header to "<title>Script Test One</title><h1>This is a test:</h1>"
  19.  
  20. -- Add some text to the body of the document
  21.  
  22. set body to "This is a test of special chars. See \"Spot\" run! Here's a backslash -> \\"
  23.  
  24. -- Show the current time on the server
  25.  
  26. set body to body & "<h2>The time is:</h2>" & (current date)
  27.  
  28. -- The following shows how to reference the args passed in from MacHTTP
  29.  
  30. set args to "<h2>Arguments passed in:</h2>" & http_request
  31. set search_args to "<h2>Search arguments:</h2>" & http_search_args
  32.  
  33. -- Show all the files in the folder "file_path" and turn HTML files into anchors
  34.  
  35. set filelist to "<h2>Files on the server:</h2><ul>"
  36. set listing to (list folder file file_path)
  37. repeat with i from 1 to the number of items in listing
  38.     set one_file to item i of listing
  39.     if one_file contains ".html" or one_file contains ".script" then
  40.         set filelist to filelist & "<li><a href=\"" & one_file & "\">" & one_file & "</a>"
  41.     else
  42.         set filelist to filelist & "<li>" & one_file
  43.     end if
  44. end repeat
  45. set filelist to filelist & "</ul>"
  46.  
  47. -- send it all back to the server for transmission to the client
  48.  
  49. return header & body & args & search_args & filelist
  50.